/*
 * GraphRect.java
 *
 * Created on 28. maaliskuuta 2007, 16:48
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package flowchart.nodes;

import java.awt.*;

/**
 *
 * @author jl
 */
public class GraphicsNode extends AbstractGraphicsObject {
    
    /** Creates a new instance of GraphRect */
    public GraphicsNode(Rectangle r) {
        setBounds((Rectangle) r.clone());
    }
    

     public GraphicsNode(String t,int x, int y) {
        this(new Rectangle(x, y, 80, 40));
        title=t;
        this.setZorder(10);
    }

     public Rectangle getBounds(FontMetrics fm){
      int sw = fm.stringWidth(this.getTitle()) + 6;
      int sh = fm.getAscent() + fm.getDescent() + 6;
      Rectangle r = new Rectangle(this.getBounds().x - sw / 2, this.getBounds().y - sh / 2, sw, sh);
      return r;
   }


    public void draw(Graphics2D g) {

       FontMetrics fm = g.getFontMetrics();
       int h = fm.getAscent();
       Rectangle r = this.getBounds();

         g.setColor(Color.white);
         g.fill(r);
         if (this.isSelected())
             g.setColor(Color.RED);
         else
         g.setColor(Color.black);
         g.draw(r);
         g.drawString(getTitle(), r.x + 3, r.y + h + 3);
    }
    
}
